package mmpathgen.util;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

public class JavaClassNameExtractor {
	
	private static List<String> fileList = new LinkedList<String>();

	public static void main(final String[] args) {
		File path = new File("D:\\workspace\\SUT.bak\\SIR_UNL\\Java\\jtopas\\versions.alt\\orig\\v3\\src");
		extractJavaClassNames(path);
	}
	
	public static List<String> extractJavaClassNames(File path) {
		List<String> clsNames = new LinkedList<String>();
		String rootPathName = path.getAbsolutePath() + File.separator;
//		System.out.println(rootPathName);
		
		for(String fileName: JavaClassNameExtractor.extractFiles(path)) {
//			System.out.println(fileName);
			fileName = fileName.replace(rootPathName, "").replace(".java", "").replace('\\', '.').replace('/', '.');
			clsNames.add(fileName);
//			System.out.println(fileName);
		}
		
		return clsNames;
	}

	public static List<String> extractFiles(File path) {

		File[] list = path.listFiles();

		for (File f: list) {
			if(f.isFile()) {
				if(f.getName().endsWith(".java"))
				fileList.add(f.getAbsolutePath());
//				System.out.println(f.getName());
			} else if(f.isDirectory()){
				extractFiles(f);
			} else {
				System.out.println("File extract error!");
			}
		}

		return fileList;
	}
}
